package code;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

import weka.core.Instances;

public class DataFiles {

	//ATTRIBUTES
	private static DataFiles dataFiles = new DataFiles();
	
	private DataFiles(){}
	
	public static DataFiles getInstance() {
        return dataFiles;
	}
	
	public FileWriter loadWriterFile(String path){
		FileWriter fichero = null;
	
		try {
			//OPEN THE FILE
			fichero= new FileWriter(path);
		} catch (IOException e) {				
			System.out.println("ERROR: Revisar path del fichero de datos");	
		} 
		return fichero;
	}

	public Instances loadDataFile(String path) throws IOException{
		//OPEN THE FILE
	   	FileReader	fi= new FileReader(path); 
		//LOAD THE INSTANCES			
		Instances data= new Instances(fi);
		//CLOSE THE FILE
		fi.close();

		//SHUFFLE THE INSTANCES: APPLY RANDOMIZE FILTER
		data = Preproceso.getInstance().randomizar(data);
		//SPECIFY THE CLASS 
		data.setClassIndex(data.numAttributes()-1);
		return data;

	}
}
